package com.faredirfare.faredroid;

import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;

public class FareDroid extends Activity implements OnClickListener{

	private MediaPlayer mp;
	private ToggleButton tb;
	private static String TAG = "FareDroid";
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fare_droid);
		tb = (ToggleButton) findViewById(R.id.toggle);
		tb.setClickable(true);
		tb.setChecked(false);
		tb.setOnClickListener(this);
	}


	@Override
	public void onClick(View view) {
		ToggleButton b = (ToggleButton) view;
		if(b.isChecked()){
			start();
			try {
				mp.start();
			} catch (Exception e) {
				Log.e(TAG, e.getMessage());
			}
		} else {
			mp.pause();
		}
		
	}
	
	private void start(){
		if(mp == null){
			mp = new MediaPlayer();
			mp = MediaPlayer.create(this, Uri.parse("http://www.faredirfare.com:8000/mpd.ogg"));
			try {
				mp.prepareAsync();
			} catch (Exception e) {
				Log.wtf(TAG, e.getMessage());
			}
			mp.start();
		}
	}
}
